package reactor;


import org.junit.Test;
import reactor.core.publisher.Flux;
import util.Util;

import java.util.Arrays;

/**
 * @author yding5
 */
public class OperatorTest {

    @Test
    public void testFilter() {
        // 2 4 6 8 10
        Flux.range(1, 10).filter(i -> i % 2 == 0).subscribe(Util::print);
    }

    @Test
    public void testBuffer() {
        // [1,2] [3,4] [5,6]
        Flux.just(1, 2, 3, 4, 5, 6).buffer(2).subscribe(Util::print);
    }

    @Test
    public void testTake() {
        // 1 2
        Flux.just(1, 2, 3, 4, 5, 7).take(2).subscribe(Util::print);
    }

    @Test
    public void testFlatMap() {
        // -1 -3 -5 -2 -4 -6
        Flux.just(Arrays.asList(1, 3, 5), Arrays.asList(2, 4, 6)).
                flatMap(x -> Flux.fromStream(x.stream().map(i -> -i))).subscribe(Util::print);
    }
}
